﻿using UnityEngine;
using System.Collections;

public class ModBlood : IModBase
{
    private UISimpleBlood uiSimpleBlood = null;

    private Vector3 offsetPos = Vector3.zero;

    public ModBlood(OwnerObj ownerObj) : base(ownerObj)
    {
        uiSimpleBlood = BloodManager.GetInstance().CreateSimpleBlood();
        uiSimpleBlood.Show();
    }

    public void SetOffsetPos(Vector3 offsetPos)
    {
        this.offsetPos = offsetPos;
    }

    public override void Load()
    {
        base.Load();
    }

    public override void UnLoad()
    {
        base.UnLoad();

        RemoveBloodUI();
    }

    public void RemoveBloodUI()
    {
        if (null != uiSimpleBlood)
        {
            uiSimpleBlood.Destroy();
            uiSimpleBlood = null;
        }
    }

    public override void Update(float deltaTime)
    {
        base.Update(deltaTime);

        if (null != uiSimpleBlood)
        {
            Vector3 headPosition = ownerObj.Get<IUnitObject>().GetPosition() + offsetPos;

            uiSimpleBlood.UpdatePosition(headPosition);

            float value = GetModule().Get<ModAttr>().GetHpPercentValue();

            uiSimpleBlood.SetValue(value);
        }
    }
}
